<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<%@ include file="/common/taglibs.jsp" %>
<div id='student_div' ></div>
<div id='score_div1' ></div>
<div id='score_div2' ></div>
<div id='score_div3' ></div>
<div id='score_div4' ></div>
<div id='score_div5' ></div>
<div id='score_div6' ></div>
<div id='score_div7' ></div>
<div id='score_div8' ></div>
<div id='score_div9' ></div>
<div id='score_div10' ></div>
<div id='score_div11' ></div>
<div id='score_div12' ></div>


<style>
.blue-row .x-grid3-cell-inner{   
    color:blue;   
}   
.red-row .x-grid3-cell-inner{   
    color:red;   
}   
.green-row .x-grid3-cell-inner{   
    color:green;   
}  
</style>

<script>
var studentField,form;
Ext.onReady(function() {
  var flag="<%=request.getParameter("flag")%>";
  form = new Ext.form.FormPanel({
	      labelAlign:'right',
	      labelWidth:80,
	      region:'north',
	      frame:true,
	      layout:'table',
	      autoWidth:true,
	      autoHeight:true,
		  items:[{  xtype:'pairfield',
				    label:'学号',
				    id:'c_student',
				    name:'studentNo',
				    click:click,
				    query:qureyStudent
				  },{xtype:'button',
				     text:'查询',
				     hidden:!("1"==flag),
				     handler:queryScore
				 },{
				    xtype:'panel',
				    id:'c_panel'
				 },{
				    xtype:'panel',
				    id:'c_panel2'
				 }]
  });
    
  form.render('student_div');	
  studentField=form.findById('c_student');
  if(flag!="1"){
	  var userAccount="<c:out value="${SessionParameter.userAccount }"/>";
	  studentField.setValue(userAccount);
	  studentField.query(null,flag);
	  studentField.hide();
	  queryScore(flag);
  }
});

var grids=[]; 
function queryScore(){
  var studentNo=studentField.getValue();
  Ext.get(document.body).mask('<fmt:message key="info.saveMsg"/>');
  Ext.Ajax.request({
  	method:'POST',
  	url:g_rootPath+'ajax/educational/queryStudentScore.html',
  	params:{studentNo:studentNo},
  	success:function(response){
  	   Ext.get(document.body).unmask();
  	   var resp=Ext.decode(response.responseText);
  	   if(resp.success==false){
  	     Ext.Msg.alert('警告','查询出错:'+resp.errorInfo);
  	     return;
  	   }
  	   var gradePoint=resp.gradePoint;
  	   var sumCredit=resp.sumCredit;
  	   var sumPassedCredit=resp.sumPassedCredit;
  	   var failedCourseCount=resp.failedCourseCount;
  	   Ext.get('c_panel2').dom.innerHTML='<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;总平均绩点:</b>'+gradePoint
  	                                     +'&nbsp;&nbsp;&nbsp;&nbsp;<b>选课学分:</b>'+sumCredit
  	                                     +'&nbsp;&nbsp;&nbsp;&nbsp;<b>实修学分:</b>'+sumPassedCredit
  	                                     +'&nbsp;&nbsp;&nbsp;&nbsp;<b>不及格门数:</b>'+failedCourseCount;
  	   Ext.get('c_panel').show();
  	   Ext.get('c_panel2').show();
  	   var semesters=resp.semesters;
  	   var scores=resp.scores;
  	   var s1=scores.length;
  	   for(var i=0;i<s1;i++){
  	     var semester=semesters[i];
  	     var schoolYearName=semester.SCHOOL_YEAR_NAME;
  	     var schoolSemesterName=semester.SCHOOL_SEMESTER_NAME;
  	     var score=scores[i];
  	     var store=new Ext.data.JsonStore({
  	       data:score,
  	       autoLoad:true,
  	       root:'rows',
  	       fields:['COURSE_NAME','COURSE_NO','COURSE_TYPE','CREDIT','GRADE_POINT','IS_PASS','SCORE','SCORE_NATURE','UPDATE_TIME']
  	     });
  	     var cm=new Ext.grid.ColumnModel([
  	        new Ext.grid.RowNumberer(),
			{header:'课号',dataIndex:'COURSE_NO',sortable: true},
			{header:'课名',dataIndex:'COURSE_NAME',width:300,sortable: true},
			{header:'成绩',dataIndex:'SCORE',sortable: true},
			{header:'学分',dataIndex:'CREDIT',sortable: true},
			{header:'绩点',dataIndex:'GRADE_POINT',sortable: true},
			{header:'是否通过',dataIndex:'IS_PASS',sortable: true},
			{header:'成绩性质',dataIndex:'SCORE_NATURE',sortable: true},
			{header:'选修必修',dataIndex:'COURSE_TYPE',sortable: true},
			{header:'更新时间',dataIndex:'UPDATE_TIME',width:300,sortable: true}
  	     ]);
  	     var div=Ext.get('score_div'+(i+1)).dom;
  	     div.innerHTML="";
  	     var grid=new Ext.grid.GridPanel({
  	       title:schoolYearName+schoolSemesterName,
  	       el:'score_div'+(i+1),
  	       stripeRows: true, 
  	       collapsible:true,
	       height:g_height*2/3,
	       frame:true,
	       viewConfig:{
	         getRowClass:function(record, index){   
                return (record.get('IS_PASS')=='N')?'red-row':'';   
             }
	       },
  	       ds:store,
  	       bbar:[{xtype: 'tbtext',align:'right', text: '<B><FONT COLOR=PURPLE>本学期绩点:'+semester.GRADE_POINT+'</FONT></B>'}],
  	       cm:cm
  	     });
  	     grid.render();
  	     grids.push(grid);
  	   }
  	   for(var j=i;j<20;j++){
	       	 var div=Ext.get('score_div'+(j+1));
	       	 if(Ext.isEmpty(div)) break;
	         div.dom.innerHTML="";
  	   }
  	},
  	failure:function(response){
  	   Ext.get(document.body).unmask();
  	}
  	
  });
}


function click(e){
 
}


function _reset(){
      Ext.get('c_panel').hide();
      Ext.get('c_panel2').hide();
 	  for(var j=0;j<20;j++){
       	 var div=Ext.get('score_div'+(j+1));
       	 if(Ext.isEmpty(div)) break;
         div.dom.innerHTML="";
 	   }  
}

function qureyStudent(e,flag){
  var sno=this.getValue();
  var pairField=this;
  if(sno==null||sno=="") return;
  Ext.Ajax.request({
    method:'POST',
    url:g_rootPath+'ajax/findStudentByNo.html',
    params:{studentNo:sno},
    success:function(response){
      var resp=Ext.decode(response.responseText);
       if(resp.success){
         pairField.setText(resp.student.studentName);
         _reset();
         var panel=Ext.get('c_panel');
         panel.dom.innerHTML='&nbsp;&nbsp;&nbsp;&nbsp;<b>系:</b>'+resp.student.collegeName+',<b>专业:</b>'+resp.student.majorName;
         if(flag!="1"){
	         panel.dom.innerHTML+=',<b>学号:</b>'+resp.student.studentNo+',<b>姓名:</b>'+resp.student.studentName;
         }
       }else{
         pairField.setValue('');
         pairField.setText('');
         Ext.Msg.alert('<fmt:message key="label.info"/>',resp.errorInfo);
         
       }
    },
    failure:function(){}
  });
}
</script>
